#include "LuaRegister.h"
#include "Device_Printer.h"
#include "Device_RFID.h"

static const struct luaL_Reg COMController [] = {
	{"PTR_Print",Lua_PTR_Print},
	{"RFID_ReadSN",Lua_RFID_ReadSN},
	{"RFID_ReadContent",Lua_RFID_ReadContent},
	{NULL,NULL}
};


int luaopen_Library_COMController_COMController_lib(lua_State *L){
	luaL_register(L,"DeviceDriver",COMController);
	return 1;
}



int Lua_PTR_Print(lua_State *L){
	int com = lua_tointeger(L,1);
	char *str = (char*)lua_tostring(L,2);
	void *h = PTR_Open(com);
	int r;

	r = PTR_Print(h,str);
	PTR_Close(h);
	lua_pushnumber(L,r);

	return 0;
}
int Lua_RFID_ReadSN(lua_State *L){
	int com = lua_tointeger(L,1);
	char str[10];
	int r;
	void *h = RFID_Open(com);
	r = RFID_ReadSN(h,str);
	RFID_Close(h);
	lua_pushstring(L,str);
	return 0;
}
int Lua_RFID_ReadContent(lua_State *L){
	int com = lua_tointeger(L,1);
	int block = lua_tointeger(L,2);
	char str[20];
	int r;
	void *h = RFID_Open(com);
	r = RFID_ReadContent(h,str,block);
	RFID_Close(h);
	lua_pushstring(L,str);
	return 0;
}